home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Applications / BuildaDudeII / BuildaDudeIIAppController.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  3.1 KB  |  161 lines

  1.  
  2. #import "BuildaDudeIIAppController.h"
  3. #import "BuildaDudeIIDoc.h"
  4. #import "WW3DWell.h"
  5.  
  6. @implementation BuildaDudeIIAppController
  7.  
  8. - init
  9. {
  10.   [super init];
  11.   docList = [[List alloc] init];
  12.   return self;
  13. }
  14.  
  15. - awake
  16. {
  17.   [super awake];
  18.   docList = [[List alloc] init];
  19.   return self;
  20. }
  21.  
  22.  
  23. - newWell:sender
  24. {
  25.    // need to make a new empty well
  26.    currentDoc = [[BuildaDudeIIDoc alloc] init];
  27.    [currentDoc setController:self];
  28.    [docList addObject:currentDoc];
  29.    [[currentDoc window] makeKeyAndOrderFront:self];
  30.  
  31.     return self;
  32. }
  33.  
  34. - (BOOL)appAcceptsAnotherFile:sender {  return YES; }
  35.  
  36. - openFile:(const char *)filename
  37. {
  38.   char         *extension; 
  39.  
  40.  
  41.   if (!filename)
  42.   {  return nil;
  43.   }
  44.  
  45.   extension = rindex((char *)filename, '.');
  46.   if (!extension)
  47.   {  return nil;
  48.   }
  49.  
  50.   // okay, we should have valid filename now.
  51.   // for whatever it is, we'll need a new well
  52.   [self newWell:self];   
  53.  
  54.   if (!strcmp(".rib", extension))
  55.   {  [[currentDoc well] buildNewShapeHierarchyFromRIBFile:filename];
  56.   }
  57.   if (!strcmp(".eve", extension))
  58.   {  [[currentDoc well] buildNewShapeHierarchyFromEveFile:filename];
  59.   }
  60.   if (!strcmp(".mdlTemplate", extension) || !strcmp(".wwModelTemplate", extension))
  61.   {  [[currentDoc well] readMdlTemplateFile:filename];
  62.   }
  63.   if (!strcmp(".mdl", extension) || !strcmp(".wwModel", extension))
  64.   {  [[currentDoc well] buildNewShapeHierarchyFromMdlFile:filename];
  65.   }
  66.   if (!strcmp(".nib", extension))
  67.   {  [[currentDoc well] loadNibForModelInterp:filename];
  68.   }
  69.  
  70.    return self;
  71. }
  72.  
  73. - open:sender
  74. {
  75.   id           theOpenPanel;
  76.   char         *filterTypes[12] = {"eve", "rib", "mdl", "wwModel", 
  77.                                    "mdlTemplate", "wwModelTemplate", 
  78.                                    "cam", "wwCamera", 
  79.                                    "scn", "wwScene", 
  80.                                    "nib",
  81.                                    NULL };
  82.  
  83.  
  84.   theOpenPanel = [OpenPanel new];
  85.   [theOpenPanel allowMultipleFiles:NO];
  86.   if (![theOpenPanel runModalForTypes:filterTypes])
  87.   {  return nil;
  88.   }
  89.  
  90.   return [self openFile:[theOpenPanel filename]];
  91. }
  92.  
  93. - close:sender
  94. {
  95.     [[[currentDoc well] window] close];
  96.     return self;
  97. }
  98.  
  99. - docIsClosing:doc
  100. {
  101.   int   i = 0, 
  102.         howMany = [docList count];
  103.   BOOL  found = NO;
  104.  
  105.  
  106.   while (!found & (i < howMany))
  107.   {  if (doc == [docList objectAt:i])
  108.      {  [docList removeObjectAt:i];
  109.         found = YES;
  110.      }
  111.      i++;
  112.   }
  113.   return self;
  114. }
  115.  
  116.  
  117. - showInfoPanel:sender
  118. {
  119.    char buf[MAXPATHLEN + 1];
  120.    id bundle;
  121.  
  122.  
  123.    if (!infoPanel)
  124.    {  bundle = [NXBundle bundleForClass:[self class]];
  125.       [bundle getPath:buf forResource:"InfoPanel" ofType:"nib"];
  126.       [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  127.    }
  128.    if (!infoPanel)
  129.    {  NXLogError("problem loading InfoPanel.nib.\n");
  130.       return nil;
  131.    }
  132.    [infoPanel makeKeyAndOrderFront:sender];
  133.  
  134.    return self;
  135. }
  136.  
  137.  
  138. // app delegate stuff...
  139.  
  140. - appDidInit:sender
  141. {
  142.   [self newWell:self];
  143.   return self;
  144. }
  145.  
  146. - (int)app:sender openFile:(const char *)filename type:(const char *)aType
  147. {
  148.    if ([self openFile:filename])
  149.    {  return YES;
  150.    }
  151.    return NO;
  152. }
  153.  
  154. - appWillTerminate:sender
  155. {
  156.    [[docList freeObjects] free];
  157.    return self;
  158. }
  159.  
  160. @end
  161.